home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr13 / aurora2c.zip / COUNTCHR.AML < prev    next >
Text File  |  1995-04-07  |  3KB  |  97 lines

  1.  
  2. // ───────────────────────────────────────────────────────────────────
  3. // The Aurora Editor v2.0
  4. // Copyright 1993-1995 nuText Systems. All Rights Reserved Worldwide.
  5. //
  6. // Count characters
  7. //
  8. // This macro counts the number of characters in current file
  9. // or in a marked block (if one exists). The total number of
  10. // characters reported is the number of bytes that the file or
  11. // marked block would occupy on disk if it were saved (including
  12. // delimiter chars).
  13. // ───────────────────────────────────────────────────────────────────
  14.  
  15.   include bootpath "define.aml"
  16.  
  17.   var total_char
  18.  
  19.   // edit windows only
  20.   if not wintype? "edit" then
  21.     msgbox "Edit windows only!"
  22.     return
  23.   end
  24.  
  25.   // if nothing is marked, then temporarily mark the whole file
  26.   if mark? then
  27.     if getcurrbuf <> getmarkbuf then
  28.       msgbox "Mark must be in current window"
  29.       return
  30.     end
  31.   else
  32.     tempmark = TRUE             // flag indicating temporary mark
  33.     markline 1 (getlines)       // mark entire file
  34.   end
  35.  
  36.   marktype = getmarktype        // get the mark type
  37.   firstline = getmarktop        // get the top line of the mark
  38.   lastline = getmarkbot         // get the bottom line of the mark
  39.   currbuf (getmarkbuf)          // make marked buffer the current buffer
  40.   pushcursor                    // save cursor position
  41.   row (getmarktop)              // goto the top of the marked block
  42.  
  43.   // do for all lines in the mark
  44.   repeat
  45.  
  46.     total_char = total_char +   // add size to total
  47.  
  48.       case marktype
  49.  
  50.         // line marks
  51.         when 'l'
  52.           getlinelen
  53.  
  54.         // column marks
  55.         when 'k'
  56.           sizeof (gettext (getmarkleft) (getmarkcols))
  57.  
  58.         // character/stream marks
  59.         otherwise
  60.           if getrow == firstline then
  61.             sizeof (gettext (getmarkleft)
  62.                           (if firstline == lastline then
  63.                              getmarkcols
  64.                            end))
  65.           elseif getrow == lastline then
  66.             sizeof (gettext 1 (getmarkright))
  67.           else
  68.             getlinelen
  69.           end
  70.       end
  71.  
  72.   until not down or getrow > lastline
  73.  
  74.   // restore cursor position
  75.   popcursor
  76.  
  77.   // compute the space that would be occupied by delimiter
  78.   // characters if the marked block was saved (zero for binary files)
  79.   if not getbinarylen then
  80.     delimitspace = getmarkrows * (sizeof (hex2bin _LineDlm))
  81.   end
  82.  
  83.   // destroy mark if temporary
  84.   if tempmark then
  85.     destroymark
  86.   end
  87.  
  88.   display
  89.  
  90.   // display the totals
  91.   shortbox (if? tempmark "Entire file: " "Marked Block: ") +
  92.            (thousands total_char + delimitspace) + " chars (" +
  93.            (thousands total_char) + " text + " +
  94.            (thousands delimitspace) + " delimiter)"
  95.          "Character Count"
  96.  
  97.